import { Form } from 'antd';
import React, { useState, useRef } from 'react';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { merchandiseRecords } from './service';
import { connect } from 'dva';
const StockReport = props => {
  const { dispatch,match } = props;
  const [columns, setColumns] = useState([
    {
      title: '商品名称',
      dataIndex: 'name',
      initialValue:match.params.name??''
    },
    {
      title: '会员名称',
      dataIndex: 'memberName',
    },
    {
      title: '数量',
      dataIndex: 'quantity',
      hideInSearch:true
    },
    {
      title: '类型',
      dataIndex: 'type',
      hideInSearch:true,
      valueEnum: {
        'in': {
          text: '入库',
          status: 'Warning',
        },
        'out': {
          text: '出库',
          status: 'Processing',
        },
      }
    },
    {
      title: '操作员姓名',
      dataIndex: 'userName',
      hideInSearch:true
    },
    {
      title: '时间',
      dataIndex: 'createTime',
      hideInSearch:true
    },
    {
      title: '备注',
      dataIndex: 'depict',
      hideInSearch:true
    }
  ]);
  const [form] = Form.useForm();
  const actionRef = useRef();

  return (
    <PageHeaderWrapper>
      <ProTable
        actionRef={actionRef}
        rowKey="id"
        params={{
        }}
        tableAlertRender={({ selectedRowKeys, selectedRows }) => (
          <div>
            已选择{' '}
            <a
              style={{
                fontWeight: 600,
              }}
            >
              {selectedRowKeys.length}
            </a>{' '}
            项
          </div>
        )}
        request={params => {
          let _params={
            pageNum:params.current,
            ...params,
          }
          if(match.params.merchandiseId){
            _params['merchandiseId'] = match.params.merchandiseId;
          }
          delete _params.current
          delete _params.name
          return merchandiseRecords(_params)
        }}
        postData={result=>result.list}
        columns={columns}
        rowSelection={{}}
      />
    </PageHeaderWrapper>
  );
};

export default connect(({ loading,cubeStockReport }) => ({
}))(StockReport);